/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.unilearn.assignment;

import au.edu.swin.unilearn.subject.SubjectEntity;
import au.edu.swin.unilearn.submission.SubmissionEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author DidierLeung
 */
@Entity
@IdClass(value = AssignmentPK.class)
@NamedQueries({
@NamedQuery(name = "findAllAssignments", query = "SELECT ae FROM AssignmentEntity ae"),
@NamedQuery(name = "findAllAssignmentForSubjectCode", query = "SELECT ae FROM AssignmentEntity ae " +
"WHERE ae.subject_code LIKE :code AND (ae.submission_status LIKE 'Open for Submission' OR " +
"ae.submission_status LIKE 'Open for marking and submission')"),
@NamedQuery(name = "findAllAssignmentForMarking", query = "SELECT ae FROM AssignmentEntity ae " +
"WHERE ae.subject_code LIKE :code AND (ae.submission_status LIKE 'Open for marking' OR " +
"ae.submission_status LIKE 'Open for marking and submission')")
})
@Table(name = "ASSIGNMENT")
public class AssignmentEntity implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @Column
    private String assignment_no;
    @Id
    @Column(name = "SUBJECT_CODE", nullable = false, updatable = false, insertable = false)
    private String subject_code;
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "SUBJECT_CODE", referencedColumnName = "SUBJECT_CODE", nullable = false)
    private SubjectEntity subjectEntity;
    @Column
    private String assignment_name;
    @Column
    private String submission_status;
    @Temporal(TemporalType.TIMESTAMP)
    private Date deadline;
    @Column
    private double penalty_rate;
    @Column
    private String source_url;
    @Column
    private String group_ass;
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date extendedDeadLine;
    @Temporal(TemporalType.TIMESTAMP)
    private Date active_date;
    @Column
    private String marking_template_URL;
    @OneToMany(mappedBy = "assignmentEntity", cascade = CascadeType.ALL)
    private List<SubmissionEntity> submissionEntityCollection;

    public AssignmentEntity()
    {
    }

    public AssignmentEntity(String assignment_no, String assignment_name,
            String subject_code, String submission_status, Date deadline,
            double penalty_rate, String source_url, String group_ass, Date extendedDeadLine,
            Date active_date, String marking_template_URL, SubjectEntity subjectEntity)
    {
        this();
        setAssignment_no(assignment_no);
        setAssignment_name(assignment_name);
        setSubject_code(subject_code);
        setSubmission_status(submission_status);
        setDeadline(deadline);
        setPenalty_rate(penalty_rate);
        setSource_url(source_url);
        setGroup_ass(group_ass);
        setExtendedDeadLine(extendedDeadLine);
        setActive_date(active_date);
        setMarking_template_URL(marking_template_URL);
        setSubjectEntity(subjectEntity);
        setSubject_code(subjectEntity.getSubject_code());
    }

    public Assignment getAssignmentData()
    {
        return new Assignment(assignment_no, assignment_name, submission_status,
                              deadline, penalty_rate, source_url, group_ass,
                              active_date, extendedDeadLine, marking_template_URL,
                              subjectEntity.getSubjectObject());
    }

    public void setAssignmentData(Assignment a)
    {
        setAssignment_no(a.getAssignment_no());
        setAssignment_name(a.getAssignment_name());
        setSubmission_status(a.getSubmission_status());
        setDeadline(a.getDeadline());
        setPenalty_rate(a.getPenalty_rate());
        setSource_url(a.getSource_url());
        setGroup_ass(a.getGroup_ass());
        setActive_date(a.getActive_date());
    }

    public String getAssignment_no()
    {
        return assignment_no;
    }

    public void setAssignment_no(String assignment_no)
    {
        this.assignment_no = assignment_no;
    }

    public String getAssignment_name()
    {
        return assignment_name;
    }

    public void setAssignment_name(String assignment_name)
    {
        this.assignment_name = assignment_name;
    }

    public String getSubject_code()
    {
        return subject_code;
    }

    public void setSubject_code(String subject_code)
    {
        this.subject_code = subject_code;
    }

    public String getSubmission_status()
    {
        return submission_status;
    }

    public void setSubmission_status(String submission_status)
    {
        this.submission_status = submission_status;
    }

    public Date getDeadline()
    {
        return deadline;
    }

    public void setDeadline(Date deadline)
    {
        this.deadline = deadline;
    }

    public double getPenalty_rate()
    {
        return penalty_rate;
    }

    public void setPenalty_rate(double penalty_rate)
    {
        this.penalty_rate = penalty_rate;
    }

    public String getSource_url()
    {
        return source_url;
    }

    public void setSource_url(String source_url)
    {
        this.source_url = source_url;
    }

    public String getGroup_ass()
    {
        return group_ass;
    }

    public void setGroup_ass(String group_ass)
    {
        this.group_ass = group_ass;
    }

    public Date getActive_date()
    {
        return active_date;
    }

    public void setActive_date(Date active_date)
    {
        this.active_date = active_date;
    }

    public SubjectEntity getSubjectEntity()
    {
        return subjectEntity;
    }

    public void setSubjectEntity(SubjectEntity subjectEntity)
    {
        this.subjectEntity = subjectEntity;
        this.subject_code = subjectEntity.getSubject_code();
    }

    public Date getExtendedDeadLine()
    {
        return extendedDeadLine;
    }

    public void setExtendedDeadLine(Date extendedDeadLine)
    {
        this.extendedDeadLine = extendedDeadLine;
    }

    public String getMarking_template_URL()
    {
        return marking_template_URL;
    }

    public void setMarking_template_URL(String marking_template_URL)
    {
        this.marking_template_URL = marking_template_URL;
    }

    public List<SubmissionEntity> getSubmissionEntityCollection()
    {
        return submissionEntityCollection;
    }

    public void setSubmissionEntityCollection(List<SubmissionEntity> submissionEntityCollection)
    {
        this.submissionEntityCollection = submissionEntityCollection;
    }
}
